//
//  CCMoveNode.h
//  Mj
//
//  Created by shuaixitao on 13-3-14.
//  Copyright (c) 2013年 Moqikaka. All rights reserved.
//

#ifndef _CC_MOVE_NODE_
#define _CC_MOVE_NODE_

#include "cocos2d.h"

USING_NS_CC;

class CCMoveNode;

typedef enum tagDragState
{
    kDragStateGrabbed,
    kDragStateUngrabbed
} DragState;

typedef void (CCObject::*SEL_CallFuncMoveNode)(CCMoveNode*);

class CCMoveNode : public CCNode, public CCTargetedTouchDelegate
{
    
public:
    CCMoveNode(void);
    virtual ~CCMoveNode(void);
    
    virtual void onEnter();
    virtual void onExit();
    
    virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
    virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
    virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
    virtual CCObject* copyWithZone(CCZone *pZone);
    virtual void touchDelegateRetain();
    virtual void touchDelegateRelease();
    
    // 设置回调操作
    void setDragDropCallback(CCObject* pSender, SEL_CallFuncMoveNode dragDropEnd);
    void setDragDropCallback(CCObject* pSender, SEL_CallFuncMoveNode dragBegan, SEL_CallFuncMoveNode dragMove, SEL_CallFuncMoveNode dragEnd);
    // 设置是否启用拖拽
    void setDragEnable(bool enable);
    // 设置拖拽时的放大效果
    void setDragZoomIn(bool enable);
    // TODO::还有待进一步实现
    void addBackgourdImage(const char* bkgName);
    void addFrameImage(const char* frameName);
    void addMasterImage(const char* masterName);
    void addBottomItem(const char* bottomName);
    //
    static CCMoveNode* create();
    
private:
    //
    CCRect rect();
    // 
    void setToTop();
    //
    bool containsTouchLocation(CCTouch* touch);
    
    CCObject* mSender;
    SEL_CallFuncMoveNode mDragBegan;
    SEL_CallFuncMoveNode mDragMove;
    SEL_CallFuncMoveNode mDragEnd;
    CCPoint mTouchBegPos;
    CCPoint mOriginPos;
    float mCurrentScale;
    bool mDragEnable;
    bool mDragZoomIn;
    DragState mDragState;
};

#endif /*(_CC_MOVE_NODE_)*/
